<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>部门管理页面</title>
</head>
<body>
<div class="hrms_dept_container">
    <!-- 导航栏-->
    <%@ include file="./commom/head.jsp"%>


    <!-- 中间部分（左侧栏+表格内容） -->
    <div class="hrms_dept_body">
        <!-- 左侧栏 -->
        <%@ include file="./commom/leftsidebar.jsp"%>

        <!-- 部门表格内容 -->
        <div class="dept_info col-sm-10">
            <div class="panel panel-success">
                <!-- 路径导航 -->
                <div class="panel-heading">
                    <ol class="breadcrumb">
                        <li><a href="#">部门管理</a></li>
                        <li class="active">部门信息</li>
                    </ol>
                </div>
                <!-- Table -->
                <table class="table table-bordered table-hover" id="dept_table">
                    <thead>
                        <th>部门编号</th>
                        <th>部门名称</th>
                        <th>部门老大</th>
                        <th>操作</th>
                    </thead>
                    <tbody>
                        <c:forEach items="${departments}" var="dept">
                            <tr>
                                <td>${dept.deptId}</td>
                                <td>${dept.deptName}</td>
                                <td>${dept.deptLeader}</td>
                                <td>
                                    <a href="${pageContext.request.contextPath }/dept/departupdate.html?deptId=${dept.deptId}" role="button" class="btn btn-primary dept_edit_btn">编辑</a>
                                    <a href="#" role="button" class="btn btn-danger dept_delete_btn">删除</a>
                                </td>
                            </tr>
                        </c:forEach>
                    </tbody>
                </table>

                <div class="panel-body">
                    <div class="table_items">
                        当前第<span class="badge">${curPageNo}</span>页，共有<span class="badge">${totalPages}</span>页，总记录数<span class="badge">${totalItems}</span>条。
                    </div>
                    <nav aria-label="Page navigation" class="pull-right">
                        <ul class="pagination">
                            <li><a href="/HRMS/dept/depart.html?pageNo=1">首页</a></li>
                            <c:if test="${curPageNo==1}">
                                <li class="disabled">
                                    <a href="#" aria-label="Previous" class="prePage" id="prePage">
                                        <span aria-hidden="true">&laquo;</span>
                                    </a>
                                </li>
                            </c:if>
                            <c:if test="${curPageNo!=1}">
                                <li>
                                    <a href="#"  class="prePage">
                                        <span aria-hidden="true">&laquo;</span>
                                    </a>
                                </li>
                            </c:if>

                           <!-- 指定页 -->
                            <c:forEach begin="1" end="${totalPages<5?totalPages:5}" step="1" var="itemPage">
                                <c:if test="${curPageNo == itemPage}">
                                    <li class="active"><a href="/HRMS/dept/depart.html?pageNo=${itemPage}">${itemPage}</a></li>
                                </c:if>
                                <c:if test="${curPageNo != itemPage}">
                                    <li><a href="/HRMS/dept/depart.html?pageNo=${itemPage}">${itemPage}</a></li>
                                </c:if>
                            </c:forEach>

                            <c:if test="${curPageNo==totalPages}">
                                <li class="disabled" class="nextPage">
                                    <a href="#" aria-label="Next">
                                        <span aria-hidden="true">&raquo;</span>
                                    </a>
                                </li>
                            </c:if>
                            <c:if test="${curPageNo!=totalPages}">
                                <li>
                                    <a href="#" aria-label="Next" class="nextPage">
                                        <span aria-hidden="true">&raquo;</span>
                                    </a>
                                </li>
                            </c:if>
                            <li><a href="/HRMS/dept/depart.html?pageNo=${totalPages}">尾页</a></li>
                        </ul>
                    </nav>
                </div>
            </div><!-- /.panel panel-success -->
        </div><!-- /.dept_info -->
    </div><!-- /.hrms_dept_body -->



</div><!-- /.hrms_dept_container -->

<script type="text/javascript">
  $(function(){
	  var curPage = ${curPageNo};
      var totalPages = ${totalPages};
      //上一页
      $(".prePage").click(function () {
    	  console.log("a");
          if (curPage > 1){
              var pageNo = curPage-1;
              $(this).attr("href", "/HRMS/dept/depart.html?pageNo="+(pageNo));
          }
      });
      //下一页
      $(".nextPage").click(function () {
          if (curPage < totalPages){
              var pageNo = curPage+1;
              $(this).attr("href", "/HRMS/dept/depart.html?pageNo="+(pageNo));
          }
      });
      
      $(".dept_delete_btn").click(function () {
          var curPage=${curPageNo};
          var delEmpId = $(this).parent().parent().find("td:eq(0)").text();
          var delEmpName = $(this).parent().parent().find("td:eq(1)").text();
          console.log(curPage,delEmpId);
          if (confirm("确认删除【" + delEmpName+ "】的信息吗？")){
              $.ajax({
                  url:"/HRMS/dept/deptdel.html?",
                  type:"get",
                  data:{"deptId":delEmpId},
                  success:function (result) {
                  	console.log(result.code);
                  	result=JSON.parse(result);
                  	console.log(result.code);
                      if (result.code == "true"){
                          alert("删除成功！");
                          window.location.href="/HRMS/dept/depart.html?pageNo="+curPage;
                      }else {
                          alert("删除失败！");
                      }
                  }
              });
          }
      });
      
  })

</script>
</body>
</html>
